import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

export default new Vuex.Store({

  state: {
    currentId:'',
    blogs: [ 
      {
        id: 1,
        author: '张三',
        title: '上机作业测试帖',
        content: "这个上机作业太难了。"
      }
    ],
  },
  mutations: {
    //第二步  定义方法（方法名需与传参时的参数名一致），将参数存入state中的变量中
    postBlog(state,b) {
      let blog = b
      state.blogs.push({
        ...blog,
        id: state.blogs.length + 1
      })

    },
    delete(state, id) {
      state.blogs.splice(id,1)
      for (var i=id;i<state.blogs.length;i++){
        state.blogs[i].id=state.blogs[i].id-1
      }
    },
    post_(state,b_){
      let i = b_.id
      console.log(i)
      state.blogs[i-1].author = b_.author
      state.blogs[i-1].title = b_.title
      state.blogs[i-1].content = b_.content
    }
  },
  actions: {

  },
})
